#include <iostream>

using std::cout;
using std::endl;

class Base
{
public:
    Base(long base = 0)
    : _base(base)
    {
        cout << "Base(long = 0)" << endl;
    }

    virtual 
    void print() const
    {
        printf("%p\n", this);
        cout << "Base::_base = " << _base << endl;
    }

    //Base *pbase2 = &derived;
    //pbase2->func1();
    void func1()
    {
        this->print();//体现出来了多态
        /* print();//体现出来了多态 */
    }

    void func2()
    {
        Base::print();
    }

    ~Base()
    {
        cout << "~Base()" << endl;
    }
private:
    long _base;
};

class Derived
: public Base
{
public:
    Derived(long base = 0, long derived = 0)
    : Base(base)
    , _derived(derived)
    {
        cout << "Derived(long = 0, long = 0)" << endl;
    }

    void print() const
    {
        cout << "Derived::_derived = " << _derived << endl;
    }

    ~Derived()
    {
        cout << "~Derived()" << endl;
    }
private:
    long _derived;
};

int main(int argc, char *argv[])
{
    cout << "sizeof(Base) = " << sizeof(Base) << endl;//8
    cout << "sizeof(Derived) = " << sizeof(Derived) << endl;//16
    Base base(10);//栈对象
    base.print();

    cout << endl;
    Derived derived(100, 200);//栈对象
    derived.print();

    cout << endl << endl;
    Base *pbase = &base;
    pbase->func1();
    pbase->func2();

    cout << endl;
    Base *pbase2 = &derived;
    pbase2->func1();//体现了多态
    pbase2->func2();

    return 0;
}

